<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加设备</title>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/common.css">

</head>
<body>
<div class="yadmin-body animated fadeIn">
    <form action="" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                设备名称
            </label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name"
                       lay-verify="required" lay-vertype="tips"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
                价格
            </label>
            <div class="layui-input-block">
                <input type="text" id="price" name="price"
                       lay-verify="required" lay-vertype="tips"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="comment" class="layui-form-label">
                详情
            </label>
            <div class="layui-input-block">
                <input type="text" id="comment" name="comment"
                       lay-verify="required" lay-vertype="tips"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="type" class="layui-form-label">
                类别
            </label>
            <div class="layui-input-block">
                <select name="type" lay-filter="type" id="type">
                    <option value="0" >休闲</option>
                    <option value="1" >益智</option>
                    <option value="2" >沉浸式</option>
                    <option value="3" >pvp</option>
                    <option value="4" >卡牌</option>
                </select>

            </div>
        </div>
        <div class="layui-form-item">
            <label for="number" class="layui-form-label">
                数量
            </label>
            <div class="layui-input-block">
                <input type="text" id="number" name="number"
                       lay-verify="required" lay-vertype="tips"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left:0;text-align:center;">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="search">添加</button>
            </div>
        </div>
    </form>
</div>
<script src="../../layui/layui.js"></script>
<script src="../../js/common.js"></script>


<script>
    layui.config({
        base: '/layui/extend/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use(['form', 'layer', 'formSelects', 'dtree'], function () {
        $ = layui.jquery;
        var form = layui.form
        form.on('submit(search)', function (form) {

            var num = 1;
            // 对表单进行初始赋值
            // 点击添加时  function toAjax() {
            var message = "";
            $.ajax({
                type: "POST",
                url: "/equipment/add/",
                data: {
                    name: $("#name").val(), price: $("#price").val(), comment: $("#comment").val()
                    ,type:$("#type option:selected").val(),number:$("#number").val(),
                },
                dataType: "json",
                async: false,
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg("成功", {icon: 6})
                    } else (res.code == 0) {
                        layer.msg("失败", {icon: 6})
                    };
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }

            });
            return false;
        });

    });

</script>

</body>
</html>